package com.xinfan.tank;

import java.util.Vector;

/**
 * @Author xin
 * @Date 2022/5/31 15:43
 * @Version 1.0
 */
public class Tank {
    private int x;
    private int y;
    private int direction;
    private int speed = 2;//控制坦克速度
    //private com.xinfan.tank.Bullet bullet;
    boolean isAlive = true;

    Bullet bullet = null;
    Vector<Bullet> bullets = new Vector<>();

    public Tank(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    //控制坦克移动
    public void moveUp() {
        if (y > 0) {
            y -= speed;
        }

    }

    public void moveDown() {
        if (y  < 690) {
            y += speed;
        }

    }

    public void moveLeft() {
        if (x > 0) {
            x -= speed;
        }

    }

    public void moveRight() {
        if (x + 60 < 1000) {
            x += speed;
        }

    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void shot() {
        switch (getDirection()) {

            case 0:
                bullet = new Bullet(getX()+20,getY(),getDirection());

                break;
            case 1:
                bullet = new Bullet(getX()+60,getY()+20,getDirection());

                break;
            case 2:
                bullet = new Bullet(getX()+20,getY()+60,getDirection());

                break;
            case 3:
                bullet = new Bullet(getX(),getY()+20,getDirection());

                break;
        }
        new Thread(bullet).start();
        bullets.add(bullet);

    }
}
